home *** CD-ROM | disk | FTP | other *** search
/ AGA Toolkit '97 / The AGA Toolkit '97.iso / programming / c / make-3.75 / default.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-07  |  10.3 KB  |  404 lines

  1. /* Data base of default implicit rules for GNU Make.
  2. Copyright (C) 1988, 89, 90, 91, 92, 93, 94, 1995 Free Software Foundation, Inc.
  3. This file is part of GNU Make.
  4.  
  5. GNU Make is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. GNU Make is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with GNU Make; see the file COPYING.  If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "make.h"
  20. #include "rule.h"
  21. #include "dep.h"
  22. #include "file.h"
  23. #include "commands.h"
  24. #include "variable.h"
  25.  
  26. /* Define GCC_IS_NATIVE if gcc is the native development environment on
  27.    your system (gcc/bison/flex vs cc/yacc/lex).  */
  28. #ifdef __MSDOS__
  29. #define GCC_IS_NATIVE
  30. #endif
  31.  
  32.  
  33. /* This is the default list of suffixes for suffix rules.
  34.    `.s' must come last, so that a `.o' file will be made from
  35.    a `.c' or `.p' or ... file rather than from a .s file.  */
  36.  
  37. static char default_suffixes[]
  38.   = ".out .a .ln .o .c .cc .C .p .f .F .r .y .l .s .S \
  39. .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo \
  40. .w .ch .web .sh .elc .el";
  41.  
  42. static struct pspec default_pattern_rules[] =
  43.   {
  44.     { "(%)", "%",
  45.     "$(AR) $(ARFLAGS) $@ $<" },
  46.  
  47.     /* The X.out rules are only in BSD's default set because
  48.        BSD Make has no null-suffix rules, so `foo.out' and
  49.        `foo' are the same thing.  */
  50.     { "%.out", "%",
  51.     "@rm -f $@ \n cp $< $@" },
  52.  
  53.     /* Syntax is "ctangle foo.w foo.ch foo.c".  */
  54.     { "%.c", "%.w %.ch",
  55.     "$(CTANGLE) $^ $@" },
  56.     { "%.tex", "%.w %.ch",
  57.     "$(CWEAVE) $^ $@" },
  58.  
  59.     { 0, 0, 0 }
  60.   };
  61.  
  62. static struct pspec default_terminal_rules[] =
  63.   {
  64.     /* RCS.  */
  65.     { "%", "%,v",
  66.     "+$(CHECKOUT,v)" },
  67.     { "%", "RCS/%,v",
  68.     "+$(CHECKOUT,v)" },
  69.  
  70.     /* SCCS.  */
  71.     { "%", "s.%",
  72.     "$(GET) $(GFLAGS) $(SCCS_OUTPUT_OPTION) $<" },
  73.     { "%", "SCCS/s.%",
  74.     "$(GET) $(GFLAGS) $(SCCS_OUTPUT_OPTION) $<" },
  75.  
  76.     { 0, 0, 0 }
  77.   };
  78.  
  79. static char *default_suffix_rules[] =
  80.   {
  81.     ".o",
  82.     "$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  83.     ".s",
  84.     "$(LINK.s) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  85.     ".S",
  86.     "$(LINK.S) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  87.     ".c",
  88.     "$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  89.     ".cc",
  90.     "$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  91.     ".C",
  92.     "$(LINK.C) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  93.     ".f",
  94.     "$(LINK.f) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  95.     ".p",
  96.     "$(LINK.p) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  97.     ".F",
  98.     "$(LINK.F) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  99.     ".r",
  100.     "$(LINK.r) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  101.     ".mod",
  102.     "$(COMPILE.mod) -o $@ -e $@ $^",
  103.  
  104.     ".def.sym", 
  105.     "$(COMPILE.def) -o $@ $<",
  106.  
  107.     ".sh",
  108.     "cat $< >$@ \n chmod a+x $@",
  109.  
  110.     ".s.o",
  111. #if !defined(M_XENIX) || defined(__GNUC__)
  112.     "$(COMPILE.s) -o $@ $<",
  113. #else    /* Xenix.  */
  114.     "$(COMPILE.s) -o$@ $<",
  115. #endif    /* Not Xenix.  */
  116.     ".S.o",
  117. #if !defined(M_XENIX) || defined(__GNUC__)
  118.     "$(COMPILE.S) -o $@ $<",
  119. #else    /* Xenix.  */
  120.     "$(COMPILE.S) -o$@ $<",
  121. #endif    /* Not Xenix.  */
  122.     ".c.o",
  123.     "$(COMPILE.c) $< $(OUTPUT_OPTION)",
  124.     ".cc.o",
  125.     "$(COMPILE.cc) $< $(OUTPUT_OPTION)",
  126.     ".C.o",
  127.     "$(COMPILE.C) $< $(OUTPUT_OPTION)",
  128.     ".f.o",
  129.     "$(COMPILE.f) $< $(OUTPUT_OPTION)",
  130.     ".p.o",
  131.     "$(COMPILE.p) $< $(OUTPUT_OPTION)",
  132.     ".F.o",
  133.     "$(COMPILE.F) $< $(OUTPUT_OPTION)",
  134.     ".r.o",
  135.     "$(COMPILE.r) $< $(OUTPUT_OPTION)",
  136.     ".mod.o",
  137.     "$(COMPILE.mod) -o $@ $<",
  138.  
  139.     ".c.ln",
  140.     "$(LINT.c) -C$* $<",
  141.     ".y.ln",
  142. #ifndef __MSDOS__
  143.     "$(YACC.y) $< \n $(LINT.c) -C$* y.tab.c \n $(RM) y.tab.c",
  144. #else
  145.     "$(YACC.y) $< \n $(LINT.c) -C$* y_tab.c \n $(RM) y_tab.c",
  146. #endif
  147.     ".l.ln",
  148.     "@$(RM) $*.c\n $(LEX.l) $< > $*.c\n$(LINT.c) -i $*.c -o $@\n $(RM) $*.c",
  149.  
  150.     ".y.c",
  151. #ifndef __MSDOS__
  152.     "$(YACC.y) $< \n mv -f y.tab.c $@",
  153. #else
  154.     "$(YACC.y) $< \n mv -f y_tab.c $@",
  155. #endif
  156.     ".l.c",
  157.     "@$(RM) $@ \n $(LEX.l) $< > $@",
  158.  
  159.     ".F.f",
  160.     "$(PREPROCESS.F) $< $(OUTPUT_OPTION)",
  161.     ".r.f",
  162.     "$(PREPROCESS.r) $< $(OUTPUT_OPTION)",
  163.  
  164.     /* This might actually make lex.yy.c if there's no %R%
  165.        directive in $*.l, but in that case why were you
  166.        trying to make $*.r anyway?  */
  167.     ".l.r",
  168.     "$(LEX.l) $< > $@ \n mv -f lex.yy.r $@",
  169.  
  170.     ".S.s",
  171.     "$(PREPROCESS.S) $< > $@",
  172.  
  173.     ".texinfo.info",
  174.     "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@",
  175.  
  176.     ".texi.info",
  177.     "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@",
  178.  
  179.     ".txinfo.info",
  180.     "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@",
  181.  
  182.     ".tex.dvi",
  183.     "$(TEX) $<",
  184.  
  185.     ".texinfo.dvi",
  186.     "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<",
  187.  
  188.     ".texi.dvi",
  189.     "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<",
  190.  
  191.     ".txinfo.dvi",
  192.     "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<",
  193.  
  194.     ".w.c",
  195.     "$(CTANGLE) $< - $@",    /* The `-' says there is no `.ch' file.  */
  196.  
  197.     ".web.p",
  198.     "$(TANGLE) $<",
  199.  
  200.     ".w.tex",
  201.     "$(CWEAVE) $< - $@",    /* The `-' says there is no `.ch' file.  */
  202.  
  203.     ".web.tex",
  204.     "$(WEAVE) $<",
  205.  
  206.     0, 0,
  207.   };
  208.  
  209. static char *default_variables[] =
  210.   {
  211.     "AR", "ar",
  212.     "ARFLAGS", "rv",
  213.     "AS", "as",
  214. #ifdef GCC_IS_NATIVE
  215.     "CC", "gcc",
  216.     "CXX", "gcc",
  217. #else
  218.     "CC", "cc",
  219.     "CXX", "g++",
  220. #endif
  221.  
  222.     /* This expands to $(CO) $(COFLAGS) $< $@ if $@ does not exist,
  223.        and to the empty string if $@ does exist.  */
  224.     "CHECKOUT,v",
  225.     "$(patsubst $@-noexist,$(CO) $(COFLAGS) $< $@,\
  226.         $(filter-out $@,$(firstword $(wildcard $@) $@-noexist)))",
  227.  
  228.     "CO", "co",
  229.     "CPP", "$(CC) -E",
  230. #ifdef    CRAY
  231.     "CF77PPFLAGS", "-P",
  232.     "CF77PP", "/lib/cpp",
  233.     "CFT", "cft77",
  234.     "CF", "cf77",
  235.     "FC", "$(CF)",
  236. #else    /* Not CRAY.  */
  237. #ifdef    _IBMR2
  238.     "FC", "xlf",
  239. #else
  240. #ifdef    __convex__
  241.     "FC", "fc",
  242. #else
  243.     "FC", "f77",
  244. #endif /* __convex__ */
  245. #endif /* _IBMR2 */
  246.     /* System V uses these, so explicit rules using them should work.
  247.        However, there is no way to make implicit rules use them and FC.  */
  248.     "F77", "$(FC)",
  249.     "F77FLAGS", "$(FFLAGS)",
  250. #endif    /* Cray.  */
  251.     "GET", SCCS_GET,
  252.     "LD", "ld",
  253. #ifdef GCC_IS_NATIVE
  254.     "LEX", "flex",
  255. #else
  256.     "LEX", "lex",
  257. #endif
  258.     "LINT", "lint",
  259.     "M2C", "m2c",
  260. #ifdef    pyr
  261.     "PC", "pascal",
  262. #else
  263. #ifdef    CRAY
  264.     "PC", "PASCAL",
  265.     "SEGLDR", "segldr",
  266. #else
  267.     "PC", "pc",
  268. #endif    /* CRAY.  */
  269. #endif    /* pyr.  */
  270. #ifdef GCC_IS_NATIVE
  271.     "YACC", "bison -y",
  272. #else
  273.     "YACC", "yacc",    /* Or "bison -y"  */
  274. #endif
  275.     "MAKEINFO", "makeinfo",
  276.     "TEX", "tex",
  277.     "TEXI2DVI", "texi2dvi",
  278.     "WEAVE", "weave",
  279.     "CWEAVE", "cweave",
  280.     "TANGLE", "tangle",
  281.     "CTANGLE", "ctangle",
  282.  
  283.     "RM", "rm -f",
  284.  
  285.     "LINK.o", "$(CC) $(LDFLAGS) $(TARGET_ARCH)",
  286.     "COMPILE.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  287.     "LINK.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  288.     "COMPILE.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  289.     "COMPILE.C", "$(COMPILE.cc)",
  290.     "LINK.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  291.     "LINK.C", "$(LINK.cc)",
  292.     "YACC.y", "$(YACC) $(YFLAGS)",
  293.     "LEX.l", "$(LEX) $(LFLAGS) -t",
  294.     "COMPILE.f", "$(FC) $(FFLAGS) $(TARGET_ARCH) -c",
  295.     "LINK.f", "$(FC) $(FFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  296.     "COMPILE.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  297.     "LINK.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  298.     "COMPILE.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -c",
  299.     "LINK.r", "$(FC) $(FFLAGS) $(RFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  300.     "COMPILE.def", "$(M2C) $(M2FLAGS) $(DEFFLAGS) $(TARGET_ARCH)",
  301.     "COMPILE.mod", "$(M2C) $(M2FLAGS) $(MODFLAGS) $(TARGET_ARCH)",
  302.     "COMPILE.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  303.     "LINK.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  304.     "LINK.s", "$(CC) $(ASFLAGS) $(LDFLAGS) $(TARGET_MACH)",
  305.     "COMPILE.s", "$(AS) $(ASFLAGS) $(TARGET_MACH)",
  306.     "LINK.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_MACH)",
  307.     "COMPILE.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_MACH) -c",
  308. #if !defined(M_XENIX) || defined(__GNUC__)
  309.     "PREPROCESS.S", "$(CC) -E $(CPPFLAGS)",
  310. #else    /* Xenix.  */
  311.     "PREPROCESS.S", "$(CC) -EP $(CPPFLAGS)",
  312. #endif    /* Not Xenix.  */
  313.     "PREPROCESS.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -F",
  314.     "PREPROCESS.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -F",
  315.     "LINT.c", "$(LINT) $(LINTFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
  316.  
  317. #ifndef    NO_MINUS_C_MINUS_O
  318. #if !defined(M_XENIX) || defined(__GNUC__)
  319.     "OUTPUT_OPTION", "-o $@",
  320. #else    /* Xenix.  */
  321.     "OUTPUT_OPTION", "-Fo$@",
  322. #endif    /* Not Xenix.  */
  323. #endif
  324.  
  325. #ifdef    SCCS_GET_MINUS_G
  326.     "SCCS_OUTPUT_OPTION", "-G$@",
  327. #endif
  328.  
  329.     0, 0
  330.   };
  331.  
  332. /* Set up the default .SUFFIXES list.  */
  333.  
  334. void
  335. set_default_suffixes ()
  336. {
  337.   suffix_file = enter_file (".SUFFIXES");
  338.  
  339.   if (no_builtin_rules_flag)
  340.     (void) define_variable ("SUFFIXES", 8, "", o_default, 0);
  341.   else
  342.     {
  343.       char *p = default_suffixes;
  344.       suffix_file->deps = (struct dep *)
  345.     multi_glob (parse_file_seq (&p, '\0', sizeof (struct dep), 1),
  346.             sizeof (struct dep));
  347.       (void) define_variable ("SUFFIXES", 8, default_suffixes, o_default, 0);
  348.     }
  349. }
  350.  
  351. /* Enter the default suffix rules as file rules.  This used to be done in
  352.    install_default_implicit_rules, but that loses because we want the
  353.    suffix rules installed before reading makefiles, and thee pattern rules
  354.    installed after.  */
  355.  
  356. void
  357. install_default_suffix_rules ()
  358. {
  359.   register char **s;
  360.   
  361.   if (no_builtin_rules_flag)
  362.     return;
  363.  
  364.  for (s = default_suffix_rules; *s != 0; s += 2)
  365.     {
  366.       register struct file *f = enter_file (s[0]);
  367.       /* Don't clobber cmds given in a makefile if there were any.  */
  368.       if (f->cmds == 0)
  369.     {
  370.       f->cmds = (struct commands *) xmalloc (sizeof (struct commands));
  371.       f->cmds->filename = 0;
  372.       f->cmds->commands = s[1];
  373.       f->cmds->command_lines = 0;
  374.     }
  375.     }
  376. }
  377.  
  378.  
  379. /* Install the default pattern rules.  */
  380.  
  381. void
  382. install_default_implicit_rules ()
  383. {
  384.   register struct pspec *p;
  385.   
  386.   if (no_builtin_rules_flag)
  387.     return;
  388.  
  389.   for (p = default_pattern_rules; p->target != 0; ++p)
  390.     install_pattern_rule (p, 0);
  391.  
  392.   for (p = default_terminal_rules; p->target != 0; ++p)
  393.     install_pattern_rule (p, 1);
  394. }
  395.  
  396. void
  397. define_default_variables ()
  398. {
  399.   register char **s;
  400.  
  401.   for (s = default_variables; *s != 0; s += 2)
  402.     (void) define_variable (s[0], strlen (s[0]), s[1], o_default, 1);
  403. }
  404.